package com.autumn.aitraffic.controller;


import com.autumn.aitraffic.api.Result;
import com.autumn.aitraffic.domain.po.AppointInfo;
import com.autumn.aitraffic.domain.vo.AppointUpVo;
import com.autumn.aitraffic.domain.vo.AppointVo;
import com.autumn.aitraffic.domain.vo.ObeyUpVo;
import com.autumn.aitraffic.service.IAppointInfoService;
import com.autumn.aitraffic.service.impl.AppointInfoServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author wzx
 * @since 2025-04-13
 */
@RestController
@RequestMapping("/appoint")
public class AppointInfoController {
    @Autowired
    private IAppointInfoService appointInfoService;

    @GetMapping("list")
    public Result getlist(int pageNum, int pageSize,
                             @RequestParam(required = false) String name
            , @RequestParam(required = false) String phoneNumber, @RequestParam(required = false) String plateNumber,
                             @RequestParam(required = false) Integer carType)
    {
        Page<AppointInfo> objectPage = new Page<>(pageNum, pageSize);
        Page<AppointInfo> page = appointInfoService.lambdaQuery().eq(!name.isEmpty(), AppointInfo::getUsername, name)
                .like(!phoneNumber.isEmpty(), AppointInfo::getPhoneNumber, phoneNumber)
                .like(!plateNumber.isEmpty(), AppointInfo::getPlateNumber, plateNumber)
                .eq(carType != null, AppointInfo::getCarType, carType)
                .page(objectPage);
        List<AppointInfo> records = page.getRecords();
        AppointVo appointVo = new AppointVo();
        appointVo.setList(records);
        appointVo.setTotal(records.size());
        return Result.succ(null,appointVo);
    }
    @PutMapping("updateStatus")
    private Result updateAppoint(@RequestBody AppointUpVo appoint){
        appointInfoService.lambdaUpdate().eq(AppointInfo::getId,appoint.getId())
                .set(AppointInfo::getAppointmentStatus,appoint.getAppointmentStatus())
                .update();
        Result result = new Result();
        return Result.succ(null,null);
    }
    @PutMapping("updateObey")
    private Result updateObey(@RequestBody ObeyUpVo obeyUpVo){
        appointInfoService.lambdaUpdate().eq(AppointInfo::getId,obeyUpVo.getId())
                .set(AppointInfo::getIsObey,obeyUpVo.getIsObey())
                .update();
        return Result.succ(null,null);
    }
}
